package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.business.domain.StockBill;
import cn.wolfcode.car.business.domain.Store;
import cn.wolfcode.car.business.query.StockBillQuery;
import cn.wolfcode.car.business.service.IGoodsService;
import cn.wolfcode.car.business.service.IStockBillService;
import cn.wolfcode.car.business.service.IStoreService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.xml.dtm.DTMDOMException;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.List;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("business/stockBill")
public class StockBillController {
    //模板前缀
    private static final String prefix = "business/stockBill/";

    @Autowired
    private IStockBillService stockBillService;
    @Autowired
    private IStoreService storeService;
    @Autowired
    private IGoodsService goodsService;

    //列表界面
    @RequestMapping("/listPage")
    public String listPage(Model model){
        List<Store> stores = storeService.selectAll();
        model.addAttribute("stores",stores);
        return prefix + "list";
    }
    //新增界面
    @RequestMapping("/addPage")
    public String addPage(){
        return prefix + "add";
    }
    //编辑界面
    @RequestMapping("/editPage")
    public String editPage(Long id, Model model){
        StockBill stockBill = stockBillService.get(id);
        model.addAttribute("stockBill",stockBill);
        return prefix +"edit";
    }
    //列表数据
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StockBill> query(StockBillQuery qo){
        return stockBillService.query(qo);
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(StockBill stockBill){
        stockBillService.save(stockBill);
        return AjaxResult.success();
    }
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(StockBill stockBill){
        stockBillService.edit(stockBill);
        return AjaxResult.success();
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id){
        stockBillService.remove(id);
        return AjaxResult.success();
    }

    @RequestMapping("/putStore")
    public String putStore(Model model){
        List<Store> stores = storeService.selectAll();
        model.addAttribute("stores",stores);
        return prefix + "putStore";
    }
    @RequestMapping("/outStore")
    public String outStore(Model model){
        List<Store> stores = storeService.selectAll();
        model.addAttribute("stores",stores);
        return prefix + "outStore";
    }

    @RequestMapping("/putStoreBill")
    @ResponseBody
    public AjaxResult putStoreBill(@RequestBody Object putStoreBill) throws ParseException {
        stockBillService.putStoreBill(putStoreBill);
        return AjaxResult.success();
    }

    @RequestMapping("/outStoreBill")
    @ResponseBody
    public AjaxResult outStoreBill(@RequestBody Object outStoreBill) throws ParseException {
        stockBillService.outStoreBill(outStoreBill);
        return AjaxResult.success();
    }





}
